<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/8/1
  Time: 15:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
    <title>包间管理</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/bootstrap/css/bootstrap.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/table/bootstrap-table.min.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/date/bootstrap-datetimepicker.min.css"/>
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/static/sweetalert.css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery-3.2.1.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/static/sweetalert.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/static/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/static/table/bootstrap-table.min.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/static/table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/date/Moment.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/static/date/bootstrap-datetimepicker.zh-CN.js"></script>

    <style type="text/css">
        .num {
            position: relative;
            bottom: 20px;
            left: 10px;
            border: 0px;
            outline: none;
            cursor: pointer;
        }
        #shop tr:not(:first-child) td{
            line-height: 50px;
        }

    </style>
</head>
<body>
<%--预约模态框--%>
<div id="reserve" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <form class="form-inline">
            <div class="panel panel-primary">
                <div class="panel-heading" style="padding-left: 45%;">预约</div>
                <div class="panel-body">
                    <div class="form-group">
                        &nbsp;&nbsp;&nbsp;&nbsp;<label for="Reservations">预约人:</label>
                           <input type="text" name="reservations" class="form-control" id="Reservations" placeholder="预约人">
                    </div>
                    <div class="form-group" style="float:right;margin-right: 32px;">
                        <label for="exampleInputEmail2">手机号:</label>
                        <input type="text" name="reservephone" class="form-control" id="exampleInputEmail2" placeholder="手机号">
                    </div>
                    <div class="form-group" style="margin-top: 15px;">
                        <label for="toroomid">桌号/包间:</label>
                        <select class="form-control" id="toroomid">
                            <option value="3">请选择</option>
                            <option value="1">桌号</option>
                            <option value="2">包间</option>
                        </select>
                    </div>
                    <div class="form-group Reserve" style="margin-top: 15px;">
                        <select class="form-control" id="roomid" name="roomid">

                        </select>
                    </div>
                    <div class="form-group" style="float:right;margin-right: 32px;margin-top: 15px;">
                        <label for="time">到店时间:</label>
                        <input id="time" type="text" class="form-control" name="arrival" placeholder="到店时间">
                    </div>
                </div>
            </div>
        </form>
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- Large modal -->
<div id="myModal" class="modal fade bs-example-modal-lg mod" tabindex="-1" role="dialog"
     aria-labelledby="myLargeModalLabel">
    <div class="modal-dialog modal-lg" style="margin-right: 50px;" role="document">
        <div class="page-header">
            <div class="modal-content">
                <h2 style="margin-left: 45%;margin-bottom: 10px;">
                    <small>菜单列表</small>
                </h2>
                <form class="form-inline" id="action" method="post" action="${pageContext.request.contextPath}/"
                      style="background-color: #fff;padding-left: 10px">
                    <div class="form-group">
                        菜名：<input id="dishesname" name="dishesname" type="text" class="form-control" placeholder="搜索内容">
                    </div>
                    状态:<select name="disheslabelid" id="disheslabelid" class="form-control">
                    <option value="0">全部</option>
                    <c:forEach items="${dishesLabels}" var="d">
                        <option value="${d.disheslabelid}">${d.disheslabel}</option>
                    </c:forEach>
                </select>
                    <input type="hidden" value="1" name="pageNumber"/>
                    <input type="hidden" value="10" name="pageSize"/>
                </form>
                <div class="panel panel-default">
                    <div class="panel-body  dishes">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<%--小模态框--%>
<div id="myModal1" class="modal fade bs-example-modal-sm mod" tabindex="-1" role="dialog" data-backdrop="false"
     aria-labelledby="mySmallModalLabel" style="width: 500px;">
    <div class="modal-dialog modal-sm" role="document"
         style="margin-left: 0px;margin-top: 40px; height: 500px;border-radius: 5px;">
        <div class="modal-content" style="background-color: white; width:500px;min-height: 500px;">
            <div style="background-color: white;border-radius: 5px;">
                <div class="panel panel-default">
                    <!-- Default panel contents -->
                    <div class="panel-heading">点菜信息</div>
                    <!-- Table -->
                    <table class="table table-hover" id="shop">
                        <thead>
                        <tr>
                            <td>菜品图片</td>
                            <td>菜品名称</td>
                            <td>菜品数量</td>
                            <td>菜品单价</td>
                            <td>菜品总价</td>
                        </tr>
                        </thead>
                        <tbody id="shop1">
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<%--结账模态框--%>
<div id="CheckOut1" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">结账列表</h4>
            </div>
            <div class="modal-body">
                <table class="table table-bordered" id="jiezhang">
                    <tr>
                        <th>包间名称</th>
                        <th>菜品名称</th>
                        <th>菜品数量</th>
                        <th>菜品单价</th>
                    </tr>
                </table>
            </div>
            <p style='margin-left: 80%;'>总金额：<span id="price" style='font-size: 18px;color: red'></span></p>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" id="CheckOut">结账</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<input type="text" style="display: none" value="1" id="tabInput">
<div class="panel panel-default">
    <div class="panel-body">
        <form class="form-inline">
            状态:<select name="roomstate" id="roomstate" class="form-control">
            <option value="3">全部</option>
            <option value="1">消费中</option>
            <option value="2">未使用</option>
        </select>
            类型:<select name="roomtype.roomtypeid" id="roomtype" class="form-control">
            <option value="10">全部</option>
            <c:forEach items="${list}" var="r">
                <option value="${r.roomtype.roomtypeid}">${r.roomtype.roomtype}</option>
            </c:forEach>
        </select>
            <button onclick="search()" type="button" class="btn btn-default">查询</button>
        </form>
    </div>
</div>
<div id="div" style="float: right">
    <button type="button" class="btn btn-primary" id="OpenBill">开单</button>
    <button type="button" class="btn btn-primary" onclick="TabTable(1)" id="dishes">菜单列表</button>
    <button type="button" class="btn btn-warning" id="ToCheckOut">结账</button>
    <button type="button" class="btn btn-warning" id="toReserve">预约</button>
</div>
<div>
    <ul class="nav nav-tabs" role="tablist">
        <li role="presentation" class="active"><a class="home" href="#home" aria-controls="home" role="tab"
                                                  onclick="TabTable(1)" data-toggle="tab">大厅</a>
        </li>
        <li role="presentation"><a href="#profile" class="profile" aria-controls="profile" role="tab"
                                   onclick="TabTable(2)" data-toggle="tab">包间</a>
        </li>
    </ul>
    <!-- Tab panes -->
    <div class="tab-content">
        <div role="tabpanel" class="tab-pane active" id="home">
            <table id="tb" class="table1" onclick="TabTable(1)"></table>
        </div>
        <div role="tabpanel" class="tab-pane" id="profile">
            <table id="tb1" class="table1" onclick="TabTable(2)"></table>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">


   /* var ws = new WebSocket("wss://echo.websocket.org");
    ws.onopen = function(evt) {
        console.log("Connection open ...");
        ws.send("Hello WebSockets!");
    };

    ws.onmessage = function(evt) {
        console.log( "Received Message: " + evt.data);
        ws.close();
    };

    ws.onclose = function(evt) {
        console.log("Connection closed.");
    };*/

    //点菜信息
    function UpMenu(id, type,count) {
        var tbroom = $("#tb").bootstrapTable("getSelections");
        var tb1room=$("#tb1").bootstrapTable("getSelections");
        var Menu = $("#shop").find("tr");
        var roomId=0;
        var dishesId=$(".dishesId");
        if(tbroom!=null){
            roomId=tbroom[0].roomid;
        }
        if(tb1room!=null){
            roomId=tbroom[0].roomid;
        }
        for(var i=0;i<dishesId.length;i++){
            console.log(dishesId[i].innerHTML)
            if(dishesId[i].innerHTML==id){
                Upajax(id,type,roomId);
            }
        }
        if(type=="create"){
            Upajax(id,type,roomId);
        }
    }

    function Upajax(id, type,roomId){
        $.ajax({
            url: "${pageContext.request.contextPath}/orderdishes/upMenu",
            data: {"dishesId": id, "type": type,"roomid":roomId},
            type: "post",
            success: function (data) {
                if(data==true){
                    showMenu();
                }else{
                    alert("服务器异常");
                }
            }
        });
    }
    //动画
    $(document).on("click", ".jia", function () {
        var img = $(this).parent().parent().parent().find("img");
        var flyElm = img.clone().css('opacity', 0.9);
        $('body').append(flyElm);
        flyElm.css({
            'z-index': 9999,
            'display': 'block',
            'position': 'absolute',
            'top': img.offset().top + 'px',
            'left': img.offset().left + 'px',
            'width': img.width() + 'px',
            'height': img.height() + 'px'
        });
        flyElm.animate({
            top: img.offset().top,
            left: img.offset().left,
            width: 39,
            height: 39
        }, '1000', function () {
            flyElm.animate({
                top: parseInt($("#shop").find("tr:last").offset().top) + 1,
                left: parseInt($("#shop").find("tr:last").offset().left) + 2
            }, '1000', function () {
                flyElm.remove();
            });
        });
    });


    /*$(document).on("click", ".jian", function () {
        var id = $(this).parent().prev().find("input");
        var flyElm = img.clone().css('opacity', 0.9);
        $('body').append(flyElm);
        flyElm.css({
            'z-index': 9999,
            'display': 'block',
            'position': 'absolute',
            'top': img.offset().top + 'px',
            'left': img.offset().left + 'px',
            'width': img.width() + 'px',
            'height': img.height() + 'px'
        });
        flyElm.animate({
            top: img.offset().top,
            left: img.offset().left,
            width: 39,
            height: 39
        }, '1000', function () {
            flyElm.animate({
                top: parseInt($(".dishes").find("div:last").offset().top) + 1,
                left: parseInt($(".dishes").find("div:last").offset().left) + 2
            }, '1000', function () {
                flyElm.remove();
            });
        });
    });*/



    function TabTable(id) {
        $("#tabInput").val(id);
    }
    var orderdishesid =[];
    var roomId ="";
    var totalAmount =0;

    $("#toReserve").click(function(){
        $("#reserve").modal("show");
    });

    $("#toroomid").change(function(){
        var roomid = $("#toroomid").val();
        if(roomid!=3){
            $.ajax({
                "url":"${pageContext.request.contextPath}/Reserve/Reserve",
                "type":"post",
                "data":{"toroomid":roomid},
                "success":function(data){
                    $("#roomid").empty();
                    for(var i=0;i<data.length;i++){
                        $("#roomid").append("<option value='"+data[i].roomid+"'>"+data[i].roomname+"</option>");
                    }
                }
            });
        }else{
            $("#roomid").empty();
        }

    });




    //去结账
    $(document).on("click","#ToCheckOut",function(){
        var select = $("#tb").bootstrapTable("getSelections");
        var select1 = $("#tb1").bootstrapTable("getSelections");
        var arry =[];
        if(select[0].roomstate==2){
            alert(select[0].roomname+"未开单");
            return;
        }
        if(select1[0].roomstate==2){
            alert(select1[0].roomname+"未开单");
            return;
        }
        if(select.length>=1){
            var roomid = [];
            var roomname = select[0].roomname;
            for(var i=0;i<select.length;i++){
                roomid +=select[i].roomid+",";
            }
            $.ajax({
                "url":"${pageContext.request.contextPath}/room/ToCheckOut",
                "type":"post",
                "data":{"roomid":roomid},
                "success":function(data){
                    if(data.length>=1){
                        var arry = [];
                        var price = 0;
                        $("#jiezhang tr:not(:first)").empty();
                        $("#price").empty();
                        for(var i =0;i<data.length;i++){
                            if(data[i].dishes!=null){
                                arry +="<tr class='empty'><td>"+data[i].room.roomname+"</td>";
                                arry +="<td>"+data[i].dishes.dishesname+"</td>";
                                arry +="<td>"+data[i].dishesnum+"</td>";
                                arry +="<td>"+data[i].dishes.dishesprice+"</td></tr>";
                                price +=data[i].dishes.dishesprice;
                                // orderdishesid += data[i].dishes.dishesid+",";
                                roomId += roomid[i]+",";
                            }else{
                                if(window.confirm(data[i].room.roomname+"还没有消费确定要结账吗？")){
                                    // totalAmount = price;
                                    // $("#price").html(price);
                                    // $("#jiezhang").append(arry);
                                    $.ajax({
                                        "url":"${pageContext.request.contextPath}/room/CheckOut",
                                        "type":"post",
                                        "data":{"roomid":select[i].roomid,"totalAmount":totalAmount},
                                        "success":function(data){
                                            $("#CheckOut1").modal("hide");
                                            roomId ="";
                                            search();
                                        }
                                    });
                                    // $('#CheckOut1').modal('show');
                                    return;
                                }else{
                                    return;
                                }
                            }
                        }
                        totalAmount = price;
                        $("#price").html(price);
                        $("#jiezhang").append(arry);
                        $('#CheckOut1').modal('show');
                    }else{
                        if(window.confirm(roomname+"还没有消费，确定要结账吗？")){
                        $.ajax({
                                "url":"${pageContext.request.contextPath}/room/CheckOut",
                                "type":"post",
                                "data":{"roomid":select[i].roomid,"totalAmount":totalAmount},
                                "success":function(data){
                                    $("#CheckOut1").modal("hide");
                                    roomId ="";
                                    search();
                                }
                            });
                        }
                    }
                }
            });
        }else if(select1.length>=1){
            var roomid = select1[0].roomid;
            var roomname = select1[0].roomname;
            $.ajax({
                "url":"${pageContext.request.contextPath}/room/ToCheckOut",
                "type":"post",
                "data":{"roomid":roomid},
                "success":function(data){
                    if(data.length>=1){
                        var arry = [];
                        var price = 0;
                        $("#jiezhang tr:not(:first)").empty();
                        $("#price").empty();
                        for(var i =0;i<data.length;i++){
                            if(data[i].dishes!=null){
                                arry +="<tr class='empty'><td>"+data[i].room.roomname+"</td>";
                                arry +="<td>"+data[i].dishes.dishesname+"</td>";
                                arry +="<td>"+data[i].dishesnum+"</td>";
                                arry +="<td>"+data[i].dishes.dishesprice+"</td></tr>";
                                price +=data[i].dishes.dishesprice;
                                // orderdishesid +=data[i].dishes.dishesid+",";
                                roomId += roomid+",";
                            }else{
                                $.ajax({
                                    "url":"${pageContext.request.contextPath}/room/CheckOut",
                                    "type":"post",
                                    "data":{"roomid":select1[i].roomid,"totalAmount":totalAmount},
                                    "success":function(data){
                                        $("#CheckOut1").modal("hide");
                                        roomId ="";
                                        search();
                                    }
                                });
                                return;
                            }

                        }
                        totalAmount = price;
                        $("#price").html(price);
                        $("#jiezhang").append(arry);
                        $('#CheckOut1').modal('show')
                    } else {
                        if (window.confirm(roomname + "还没有消费，确定要结账吗？")) {
                            //未写完
                        $.ajax({
                                "url":"${pageContext.request.contextPath}/room/CheckOut",
                                "type":"post",
                                "data":{"roomid":select1[i].roomid,"totalAmount":totalAmount},
                                "success":function(data){
                                    $("#CheckOut1").modal("hide");
                                    roomId ="";
                                    search();
                                }
                            });
                        }
                    }
                }
            });
        }else if(select.length==0){
            alert("请选中需要结账的桌号！");
        } else if(select1.length==0){
            alert("请选中需要结账的包间！");
        } else if(select.length>=2||select1.length>=2){

        }
    });
    //结账
    $("#CheckOut").click(function(){
        $.ajax({
            "url":"${pageContext.request.contextPath}/room/CheckOut",
            "type":"post",
            "data":{"roomid":roomId,"totalAmount":totalAmount},
            "success":function(data){
                $("#CheckOut1").modal("hide");
                roomId ="";
                search();
            }
        });
    });
    function queryParams(params) {
        var temp = {  //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
            pageSize: params.pageSize,  //页面大小
            pageNumber: params.pageNumber, //页码
            roomstate: $("#roomstate").val(),
            roomtyperoomtypeid: $("#roomtype").val(),
            tabinput: $("#tabInput").val()
        };
        return temp;
    }

    $(document).on("click", ".modal-backdrop", function () {
        $(".mod").modal("hide");
    });
    $("#dishes").click(function () {
        showMenu();
    });

    //显示菜单
    function showMenu(){
        var select = $("#tb").bootstrapTable("getSelections");
        var select1 = $("#tb1").bootstrapTable("getSelections");
        var dishesname = $("#dishesname").val();
        $("#action").append("<input name='roomid' style='display: none' value='" + select[0].roomid + "'/>");
        var disheslabelid = $("#disheslabelid").val();
        if (select.length < 2) {
            $('.mod').modal('show');
            $("#shop1").empty();
            var entId = $(".table1").bootstrapTable("getSelections");
            var Menu = $("#shop").find("tr");
            $.ajax({
                "url": "${pageContext.request.contextPath}/room/OrderDishes",
                "type": "post",
                "data": {"roomid": select[0].roomid, "disheslabelid": disheslabelid,"dishesname":dishesname},
                "success": function (data) {
                    var dishes1 = data.dishes;
                    $(".dishes").empty();
                    var arry = "";
                    var rowid=0;
                    var pd=0;
                    for (var i = 0; i < dishes1.length; i++) {
                        pd=0;
                        arry += "<div class='row'style='display: inline-block;width: 200px;' >";
                        arry+="<input name='"+ dishes1[i].dishesId+"' style='display:none'/>";
                        arry += "<div  style='display: inline-block:width: 180px;' class='col-sm-6 col-md-4' >";
                        arry += "<div style='display: inline-block;width: 150px;margin-left: 15px' class='thumbnail'>";
                        arry += "<img src ='${pageContext.request.contextPath}" + "/static/" + dishes1[i].dishesimg + "'>";
                        arry += "<div style='display: inline-block' class='caption'>";
                        arry += "<h3 style='width: 120px;text-align: center;margin-bottom: 30px;'>" + dishes1[i].dishesname + "</h3>";
                        if(data.orderdishes!=null){
                                for(var d=0;d<data.orderdishes.length;d++){
                                        if(data.orderdishes[d].dishes.dishesid==dishes1[i].dishesid&&pd==0){
                                            arry += "<div class='btn-group-vertical count' role=\"group\" style='margin-top: -40px;px; width:20px;height:40px;'><button  type=\"button\" class='btn btn-default count jia' style='padding:0 0 ; display: table-cell;height:20px;line-height:12px;'onclick='UpMenu(" + data.orderdishes[d].dishes.dishesid + ",\"jia\","+data.orderdishes[d].dishesnum+")'>+</button>" +
                                                "<button type=\"button\"  style='display: table-cell;height:20px;line-height:13px;text-align:center;padding:0 0 ;' onclick='UpMenu(" + data.orderdishes[d].dishes.dishesid + ",\"jian\","+data.orderdishes[d].dishesnum+")'  class='btn btn-default count jian'>-</button></div><input type='text' style='width: 15px;height:30px;text-align: center;padding-top:20px'' value='"+data.orderdishes[d].dishesnum+"'  class='num'/>";
                                            arry += "<span style='width: 50px;margin-left: 70px;margin-top: -20px;display: block;color: red;font-size: 20px;'>" + dishes1[i].dishesprice + "元</span></div></div></div></div>";
                                            pd=1;
                                            break;
                                    }else{
                                       continue;
                                    }
                                }
                                if(pd==0){
                                    arry+="<button type=\"button\" class=\"btn btn-warning\" onclick='UpMenu("+dishes1[i].dishesid+",\"create\",0)' style='width:50px;'>点菜</button>";
                                    arry+= "<span style='width: 50px;margin-left: 70px;margin-top: -20px;display: block;color: red;font-size: 20px;'>" + dishes1[i].dishesprice + "元</span></div></div></div></div>";
                                }
                        }else{
                            arry+="<button type=\"button\" class=\"btn btn-warning\" onclick='UpMenu("+dishes1[i].dishesid+",\"create\",0)' style='width:50px;'>点菜</button>";
                            arry+= "<span style='width: 50px;margin-left: 70px;margin-top: -20px;display: block;color: red;font-size: 20px;'>" + dishes1[i].dishesprice + "元</span></div></div></div></div>";
                        }
                    }
                    $(".dishes").append(arry);
                    if(data.orderdishes!=null){
                        var menu=data.orderdishes
                        for(var i=0;i<menu.length;i++){
                            var sname=menu[i].dishes.dishesname;
                            var price=menu[i].dishes.dishesprice;
                            var num=menu[i].dishesnum;
                            var menu1="<tr><td><img style='width:50;height:50;' src='${pageContext.request.contextPath}/static/"+menu[i].dishes.dishesimg+"'/></td>";
                            menu1+="<td>"+sname+"</td>";
                            menu1+="<td class='dishesId' style='display:none;'>"+menu[i].dishes.dishesid+"</td>";
                            menu1+="<td><button  type=\"button\" class='btn btn-default count jia' style='padding:0 0 ; display: table-cell;height:20px;line-height:12px;width:20px;'onclick='UpMenu("+ menu[i].dishes.dishesid + ",\"jia\","+num+")'>+</button>"+num+"";
                            menu1+="<button type=\"button\"  style='display: table-cell;height:20px;line-height:13px;text-align:center;padding:0 0 ;width:20px;' onclick='UpMenu(" +menu[i].dishes.dishesid + ",\"jian\","+num+")'  class='btn btn-default count jian'>-</button></td>";
                            menu1+="<td>"+price+"</td>";
                            menu1+="<td>"+ parseFloat(num) * parseFloat(price)+"</td></tr>";
                            $("#shop").append(menu1);
                        }
                    }
                }
            });
        } else {
            if (select[0].roomstate == 2) {
                alert("只能给消费包间点菜！");
            } else {
                alert("只能给一个包间点菜！");
            }
          }
    }


    // 开单
    $("#OpenBill").click(function () {
        var select = $("#tb").bootstrapTable("getSelections");
        var select1 = $("#tb1").bootstrapTable("getSelections");
        var tabinput = $("#tabInput").val();
        var arry = "";
        if (select.length == 1 || select1.length == 1) {
            if (tabinput == 1) {
                if (select.length <= 1) {
                    for (var i = 0; i < select.length; i++) {
                        if (select[i].roomstate == 2) {
                            arry += select[i].roomid + ",";
                        } else {
                            alert(select[i].roomname + "正在消费中!");
                            return;
                        }
                    }
                } else {
                    alert("只能给一个包间或桌号开单!");
                    return;
                }
                if (window.confirm("是否要点菜？")) {
                    $.ajax({
                        "url": "${pageContext.request.contextPath}/room/OpenBill",
                        "type": "post",
                        "data": {"arry": arry},
                        "success": function (data) {
                            if (data == "ok") {
                                search()
                            }
                        }
                    });
                    showMenu();
                   /* var disheslabelid = $("#disheslabelid").val();
                    var select1 = $("#tb").bootstrapTable("getSelections");
                    $("#action").append("<input name='roomid' style='display: none' value='" + select1[0].roomid + "'  />");
                    $.ajax({
                        "url":"${pageContext.request.contextPath}/room/OrderDishes",
                        "type":"post",
                        "data":{"roomid":select1[0].roomid,"disheslabelid": disheslabelid},
                        "success":function(data){
                            var dishes = data.dishes;
                            $(".dishes").empty();
                            var arry = "";
                            for (var i = 0; i < dishes.length; i++) {
                                arry += "<div class='row'style='display: inline-block;width: 200px;' >";
                                arry += "<div  style='display: inline-block:width: 180px;' class='col-sm-6 col-md-4' >";
                                arry += "<div style='display: inline-block;width: 150px;margin-left: 15px' class='thumbnail'>";
                                arry += "<img src ='${pageContext.request.contextPath}" + "/static/" + dishes[i].dishesimg + "'>";
                                arry += "<div style='display: inline-block' class='caption'>";
                                arry += "<h3 style='width: 120px;text-align: center;margin-bottom: 30px;'>" + dishes[i].dishesname + "</h3>";
                                arry += "<p style='position: absolute;'><input type='text'   style='width: 30px;height:30px;text-align: center' value='0'  class='num'  /> <input type='button' class='jia' value='+' /><input type='button'class='jian' value='-' />";
                                arry += "</p><span style='width: 50px;margin-left: 70px;margin-top: -20px;display: inline-block;color: red;font-size: 20px;'>" + dishes[i].dishesprice + "元</span></div></div></div></div>";
                            }
                            $(".dishes").append(arry);
                        }
                    });*/
                    $('.mod').modal('show');
                } else {
                    $.ajax({
                        "url": "${pageContext.request.contextPath}/room/OpenBill",
                        "type": "post",
                        "data": {"arry": arry},
                        "success": function (data) {
                            if (data == "ok") {
                                search()
                            }
                        }
                    });
                }
            }
        } else if (select.length >= 2 || select1.length >= 2) {
            alert("只能给一个包间或桌号开单!");
            return;
        } else if (select.length >= 0 || select1.length >= 0) {
                alert("请选择一个包间或桌号开单!");
                return;
            }
    });
    function search() {
        var opts = $(".table").bootstrapTable('getOptions');
        var roomstate = $("#roomstate").val();
        var roomtyperoomtypeid = $("#roomtype").val();
        var tabinput = $("#tabInput").val();
        $.ajax({
            "url": "${pageContext.request.contextPath}/room/query",
            "type": "post",
            "data": {
                "roomstate": roomstate,
                "roomtyperoomtypeid": roomtyperoomtypeid,
                "pageNumber": 1,
                "pageSize": 5,
                "tabinput": tabinput
            },
            "dataType": "json",
            "success": function (data) {
                $(".table").bootstrapTable('load', data);
            }
        })
    }

    window.operateEvents = {
        <%--"click .toadd": function (e, value, row, index) {--%>
            <%--var tabinput = $("#tabInput").val();--%>
            <%--if (tabinput == 1 && row.state == 1) {--%>
                <%--var starTime = row.starTime;--%>
                <%--var endTime = row.endTime;--%>
                <%--$.ajax({--%>
                    <%--"url": '${pageContext.request.contextPath}/case/toAddCase',--%>
                    <%--"data": {"starTime": starTime, "endTime": endTime},--%>
                    <%--"type": "post",--%>
                    <%--"dataType": "json",--%>
                    <%--"success": function (data) {--%>
                        <%--location.href = "${pageContext.request.contextPath}/case/toCase?data=" + data;--%>
                    <%--}--%>
                <%--})--%>
            <%--}--%>
        <%--}--%>
    };

    // $(".del").click(function(){
    //
    // });
    function del(id) {
        swal({
            title: "您确定要删除这条信息吗",
            text: "删除后将无法恢复，请谨慎操作！",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "删除",
            closeOnConfirm: true
        }, function () {
            $.ajax({
                "url": '${pageContext.request.contextPath}/room/del',
                "type": "post",
                "data": {"roomid": id},
                "success": function (data) {
                    $(".table").bootstrapTable('refresh');
                }
            })
        });
    }



    $(".home").bind("click", function () {
        search();
    });
    $(".profile").bind("click", function () {
        search();
    });
    $(function () {



        //菜单列表多条件查询
        $("#disheslabelid,#dishesname").bind("change", function () {
           /* var disheslabelid = $("#disheslabelid").val();
            var dishesname = $("#dishesname").val();
            var roomid = $("input[name=roomid]").last().val();
            $.ajax({
                "url":"${pageContext.request.contextPath}/room/OrderDishes",
                "type":"post",
                "data":{"disheslabelid":disheslabelid,"dishesname":dishesname,"roomid":roomid},
                "success":function(data){
                    var dishes = data.dishes;
                    $(".dishes").empty();
                    var arry = "";
                    for (var i = 0; i < dishes.length; i++) {
                        arry += "<div class='row'style='display: inline-block;width: 200px;' >";
                        arry += "<div  style='display: inline-block:width: 180px;' class='col-sm-6 col-md-4' >";
                        arry += "<div style='display: inline-block;width: 150px;margin-left: 15px' class='thumbnail'>";
                        arry += "<img src ='${pageContext.request.contextPath}" + "/static/" + dishes[i].dishesimg + "'>";
                        arry += "<div style='display: inline-block' class='caption'>";
                        arry += "<h3 style='width: 120px;text-align: center;margin-bottom: 30px;'>" + dishes[i].dishesname + "</h3>";
                        arry += "<p style='position: absolute;'><input type='text'   style='width: 30px;height:30px;text-align: center' value='0'  class='num'  /> <input type='button' class='jia' value='+' /><input type='button'class='jian' value='-' />";
                        arry += "</p><span style='width: 50px;margin-left: 70px;margin-top: -20px;display: inline-block;color: red;font-size: 20px;'>" + dishes[i].dishesprice + "元</span></div></div></div></div>";
                    }
                    $(".dishes").append(arry);
                    $("#tb").bootstrapTable('refresh');
                    $("#tb1").bootstrapTable('refresh');
                }
            });*/
            showMenu();
        });

        //包间
        //bootstrapTable
        $(".table1").bootstrapTable({
            url: '${pageContext.request.contextPath}/room/query',
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'roomid',
                    title: '编号',
                    width: "250px"
                }, {
                    field: 'roomname',
                    title: '名称',
                    width: "250px"
                }, {
                    title: '类型',
                    formatter: function (index, row, value) {
                        return row.roomtype.roomtype;
                    },
                    width: "250px"
                }, {
                    title: '状态',
                    formatter: function (index, row, value) {
                        if (row.roomstate == 1) {
                            return "消费中"
                        } else if (row.roomstate == 2) {
                            return "未使用"
                        }
                    },
                    width: "250px"
                }, {
                    title: '操作',
                    events: operateEvents,
                    formatter: caozuo
                }],
            clickToSelect: true,
            method: 'post',
            contentType: "application/x-www-form-urlencoded",
            height: 500,
            pageList: [5, 10, 15],
            pageSize: 5,
            pageNumber: 1,
            pagination: true,
            queryParamsType: '',
            queryParams: queryParams,
            sidePagination: 'server'

        });
        function caozuo(value, row, index) {
            var tabinput = $("#tabInput").val();
            return [
                "<a class='del' href=javascript:del(" + row.roomid + ")>删除</a>"
            ].join("");
        }


        // 时间插件
        $('#time').datetimepicker({
            format: 'yyyy-mm-dd hh:ii:ss',
            autoclose: true,
            minView: 0,
            minuteStep:1
        });

    });
</script>
</html>
